﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        public void TSTVA06(DataSet db)
        {
            try
            {

                DataTable dtSoruce = db.Tables["VAART"];
                DataTable dtOutput = new DataTable();
                int idx = 1;
                double value=0;
                exAgent.SetCellValue(2, idx++, "图片"); dtOutput.Columns.Add("PHOTOLINK", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "季节"); dtOutput.Columns.Add("VAAKOLL", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "品种"); dtOutput.Columns.Add("VAAART", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "简述"); dtOutput.Columns.Add("VAAKURZBEZ", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "描述"); dtOutput.Columns.Add("VAABEZ", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "产品组"); dtOutput.Columns.Add("VAAPRGR", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "品种组"); dtOutput.Columns.Add("VAAARTGRP", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "幅宽"); dtOutput.Columns.Add("WAFBRTU", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "可用幅宽"); dtOutput.Columns.Add("WAFBRTL", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "克重G/M"); dtOutput.Columns.Add("WAFGRLFD", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "克重G/M2"); dtOutput.Columns.Add("WAFGRQM", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "经密"); dtOutput.Columns.Add("WAFFDDIK", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "纬密"); dtOutput.Columns.Add("WAFFDDIS", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "单位"); dtOutput.Columns.Add("WAFDDIM", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "供应商品种"); dtOutput.Columns.Add("VAADART", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "单价"); dtOutput.Columns.Add("WABIND", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "供应商"); dtOutput.Columns.Add("LSLIEFNA", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "参考售价"); dtOutput.Columns.Add("VAAARTWEB", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "成份"); dtOutput.Columns.Add("VAAFILLER", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "更改"); dtOutput.Columns.Add("VAAAENDBEN", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "日期"); dtOutput.Columns.Add("VAAAENDDAT", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "创建"); dtOutput.Columns.Add("VAANEUBEN", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "日期"); dtOutput.Columns.Add("VAANEUDAT", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "备注"); dtOutput.Columns.Add("REM", typeof(System.String)); 
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                foreach (DataRow rx in dtOutput.Rows)
                {
                    rx["VAABEZ"] = GetGB2312Value(rx["VAABEZ"].ToString().Trim());
                    rx["LSLIEFNA"] = GetGB2312Value(rx["LSLIEFNA"].ToString().Trim());
                    rx["REM"] = GetGB2312Value(rx["REM"].ToString().Trim());
                    value = System.Convert.ToDouble(rx["WAFBRTU"].ToString().Trim())*0.1;
                    rx["WAFBRTU"] = value.ToString();
                    value = System.Convert.ToDouble(rx["WAFBRTL"].ToString().Trim()) * 0.1;
                    rx["WAFBRTL"] = value.ToString();
                    value = System.Convert.ToDouble(rx["WAFFDDIK"].ToString().Trim()) * 0.01;
                    rx["WAFFDDIK"] = value.ToString();
                    value = System.Convert.ToDouble(rx["WAFFDDIS"].ToString().Trim()) * 0.01;
                    rx["WAFFDDIS"] = value.ToString();
                }
                exAgent.DataTableToExcel(dtOutput, 3, 1);
                int x = 2;
                int y = 0;
                foreach (DataRow rx in dtOutput.Rows)
                {
                    x++; y = 1;
                    string str = rx["PHOTOLINK"].ToString();
                    EventDispatcher.Instance.RaiseStatus(str, StatusEventType.RunningProgress);
                    if (System.IO.File.Exists(str))
                    {
                        str = str.Replace("/", "\\");
                        exAgent.SetCellsPicture(x, y, str, 40, 60);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }

    }
}